package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoFrozenReasonVO;
import com.yunxi.sto.service.StoFrozenReasonDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 车辆冻结原因 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/admin/stoFrozenReason")
@Api(tags = "sto:frozenReason", description = "车辆冻结原因接口")
public class StoFrozenReasonController {
 private static final Logger logger = LoggerFactory.getLogger(StoFrozenReasonController.class);

 @Autowired
 StoFrozenReasonDubboService stoFrozenReasonDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 public ApiResult page(StoFrozenReasonVO stoFrozenReasonVO, @RequestParam(required = true)Integer pageNum, @RequestParam(required = true)Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoFrozenReasonDubboService.findPageByVO(stoFrozenReasonVO,pageNum,pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 public ApiResult load(StoFrozenReasonVO stoFrozenReasonVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoFrozenReasonDubboService.getById(stoFrozenReasonVO.getFrozenReasonId()));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoFrozenReasonVO stoFrozenReasonVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoFrozenReasonVO.setCreateBy(loginInfo.getUserCode());
  stoFrozenReasonVO.setUpdateBy(loginInfo.getUserCode());
  stoFrozenReasonDubboService.saveOrUpdate(stoFrozenReasonVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "作废")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoFrozenReasonDubboService.delAndReset(list,1,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "恢复")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoFrozenReasonDubboService.delAndReset(list,0,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @GetMapping("/reasonList")
 @ApiOperation(value = "冻结原因列表")
 public ApiResult reasonList() throws Exception {
  return ResponseUtil.ok(stoFrozenReasonDubboService.reasonList());
 }

}
